package com.ewzj.bigdata.mvp.ui.activity

import android.content.Intent
import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.view.Window
import android.view.WindowManager
import com.bumptech.glide.Glide

import com.ewzj.bigdata.R
import com.ewzj.bigdata.app.utils.Apputils
import com.ewzj.bigdata.di.component.DaggerLogoComponent
import com.ewzj.bigdata.di.module.LogoModule
import com.ewzj.bigdata.mvp.contract.LogoContract
import com.ewzj.bigdata.mvp.model.rspbean.AdBean
import com.ewzj.bigdata.mvp.presenter.LogoPresenter
import com.jakewharton.rxbinding2.view.RxView
import com.jess.arms.base.BaseActivity
import com.jess.arms.di.component.AppComponent
import com.jess.arms.utils.DeviceUtils
import io.reactivex.Observable
import kotlinx.android.synthetic.main.activity_logo.*

class LogoActivity() : BaseActivity<LogoPresenter>() ,LogoContract.View{
    override fun initData(savedInstanceState: Bundle?) {
            mPresenter.initBdLocation()
          if (DeviceUtils.hasInternet(applicationContext)){

              mPresenter.configInfo()
              mPresenter.updateInfo()
              mPresenter.saveCity()
//              mPresenter.getAdList()
          }else{
              mPresenter.lanuchActivity()
          }

    }

    override fun setupActivityComponent(appComponent: AppComponent?) {
        DaggerLogoComponent.builder().appComponent(appComponent)
                .logoModule(LogoModule(this))
                .build().inject(this)
    }

    override fun initView(savedInstanceState: Bundle?): Int {
        // 隐藏标题栏
        requestWindowFeature(Window.FEATURE_NO_TITLE)
        // 隐藏状态栏
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN)
        return R.layout.activity_logo
    }

    override fun showLoading() {

    }

    override fun launchActivity(intent: Intent?) {

    }

    override fun hideLoading() {

    }

    override fun killMyself() {

    }

    override fun showMessage(message: String?) {

    }

    override fun useFragment(): Boolean {
        return false
    }

    override fun setLogoview(adbean: AdBean) {
        Glide.with(this).load(Apputils.Utils.getImgUrl(adbean.list!![0].images[0].img_path)).asBitmap().into(iv_logoview)
        RxView.clicks(iv_logoview).subscribe({
            mPresenter.goMainActivity()
            WebViewActivity.startWebView(this,"",adbean.list!![0].images[0].go_url)
            finish()
        })

        RxView.clicks(tvtime).subscribe({
           mPresenter.goMainActivity()
        })

    }

    override fun settvTimeview(long: Long) {
        tvtime.setText("跳过广告"+(5-long)+"s")
    }

    override fun onDestroy() {
        mPresenter.onDestroy()
        super.onDestroy()
    }
}
